package com.sdp.wx.db.wx_warehouse_right.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdp.wx.db.wx_warehouse_right.entity.WxWarehouseRight;
import com.sdp.wx.db.wx_warehouse_right.mapper.WxWarehouseRightMapper;
import com.sdp.wx.db.wx_warehouse_right.service.IWxWarehouseRightService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsp
 * @since 2024-01-20
 */
@Service
public class WxWarehouseRightServiceImpl extends ServiceImpl<WxWarehouseRightMapper, WxWarehouseRight> implements IWxWarehouseRightService {

	@Override
	public boolean isHaveRight(String empNo, String warehouseCode,String rightType) {
		LambdaQueryWrapper<WxWarehouseRight> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(WxWarehouseRight::getEmpNo, empNo);
		queryWrapper.eq(WxWarehouseRight::getWarehouseCode, warehouseCode);
		WxWarehouseRight wxWarehouseRight = getOne(queryWrapper,false);
		if(wxWarehouseRight==null || StringUtils.isEmpty(wxWarehouseRight.getWarehouseRight())) {
			return false;
		}
		boolean flag = false;
		String right[] = wxWarehouseRight.getWarehouseRight().split(",");
		for(int i=0;i<right.length;i++) {
			if(rightType.equals(right[i])) {
				flag = true;
				break;
			}
		}
		return flag;
//		return Arrays.binarySearch(right, empNo)>0?true:false;
	}

}
